package engine.utils
{
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.display.DisplayObject;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class GeomUtils
	{
		/**
		 * Creates a Point with random (x, y) values within a given range.
		 */
		public static function randomPoint(minX:Number, minY:Number, maxX:Number, maxY:Number):Point
		{
			return new Point(MathUtils.randomNumber(minX, maxX), MathUtils.randomNumber(minY, maxY));
		}
		
		/**
		 * Returns a Point with random (x, y) values within the inner bounds of a given Rectangle.
		 */
		public static function randomInnerPoint(rect:Rectangle):Point
		{
			return randomPoint(rect.left, rect.top, rect.right, rect.bottom);
		}
		
		/**
		 * Returns a Point with random (x, y) values within the outer bounds of a given Rectangle.
		 */
		public static function randomOuterPoint(rect:Rectangle, width:Number, height:Number):Point
		{
			var point:Point = new Point();
			
			if(Math.random() < 0.5) point.x = MathUtils.randomNumber(rect.left - width, rect.left);
			else point.x = MathUtils.randomNumber(rect.right, rect.right + width);
			
			if(Math.random() < 0.5) point.y = MathUtils.randomNumber(rect.top - height, rect.top);
			else point.y = MathUtils.randomNumber(rect.bottom, rect.bottom + height);
			
			return point;
		}
		
		/**
		 * Returns a Point a given distance and angle away from a starting Point.
		 */
		public static function offsetPoint(point:Point, distance:Number, angle:Number, isDegrees:Boolean = true):Point
		{
			if(isDegrees) angle = MathUtils.toRadians(angle);
			
			var offset:Point = new Point();
			offset.x = Math.cos(angle) * distance + point.x;
			offset.y = Math.sin(angle) * distance + point.y;
			
			return offset;
		}
			
		/**
		 * Calculates the distance between 2 coordinates represented by (x1, y1) and (x2, y2).
		 */
		public static function distance(x1:Number, y1:Number, x2:Number, y2:Number):Number
		{
			var deltaX:Number = x1 - x2;
			var deltaY:Number = y1 - y2;
			return Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
		}
	}
}